using LinearAlgebra

function setmin(x, xmin)
    ni, nj = size(x)
    for i ∈ 1:ni
        for j ∈ 1:nj
            if x[i, j] < xmin
                x[i, j] = xmin
            end
        end
    end
    return x
end

function within_tolerance(x1, x2, tol)
    y1 = vec(x1)
    y2 = vec(x2)

    for i ∈ 1:length(y1)
        if abs(y1[i] - y2[i]) > tol
            return false
        end
    end
    return true
end
#=
x1 = [1 2 3]
x2 = [1.1, 2.1, 3.1]
tol = 0.2
if within_tolerance(x1, x2, tol)
    print("Works 1D")
end

x1 = [1 2; 3 4]
x2 = [1.1 2.1; 3.1 4.1]
tol = 0.2
if within_tolerance(x1, x2, tol)
    print("Works 2D")
end
=#



function fast_aggregate(X, Y)
    T = X.shape[1]
    Xnew = reshape(X, T, :)
    Ynew = reshape(Y, T, :)
    Z = Vector{Float64}(undef, T)
    for t ∈ 1:T
        Z[t] = dot(Xnew[t, :], Ynew[t, :])
    end
    return Z
end
        
